//
//  IGTimeRepetitionVC.m
//  jingdongfang
//
//  Created by MTiMac01 on 2017/11/17.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "IGTimeRepetitionVC.h"

@interface IGTimeRepetitionVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) IGTimeSwitch *model;
@end

@implementation IGTimeRepetitionVC

- (instancetype)initWithModel:(IGTimeSwitch *)model
{
    self = [super init];
    if (self)
    {
        self.model = model;
    }
    return self;
}

- (void)ig_leftBackButtonPressed:(id)sender
{
    self.block(self.model);
    [super ig_leftBackButtonPressed:sender];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor mainBackgroundColor];
//    self.title = @"重复";
    self.title = NSLocalizedString(@"Repeat", nil);
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorInset = UIEdgeInsetsMake(0, -100, 0, 0);
    }
    return _tableView;
}

#pragma mark -<UITableViewDelegate, UITableViewDataSource>
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10.0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    self.model.type = [NSString stringWithFormat:@"%ld", indexPath.row];
    [self.tableView reloadData];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"IGScreenModelVCID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    cell.textLabel.font = [UIFont font16];
    cell.textLabel.textColor = [UIColor c4Color];
    UIImageView *acc = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 13, 9)];
    acc.contentMode = UIViewContentModeScaleAspectFit;
    if (indexPath.row == 0)
    {
//        cell.textLabel.text = @"每天";
        cell.textLabel.text = NSLocalizedString(@"Daily", nil);
        acc.image = [self.model.type isEqualToString:@"0"] ? [UIImage imageNamed:@"iGallery_select"] : nil;
        cell.accessoryView = acc;
    }
    else if (indexPath.row == 1)
    {
//        cell.textLabel.text = @"工作日";
        cell.textLabel.text = NSLocalizedString(@"Working Day", nil);
        acc.image = [self.model.type isEqualToString:@"1"] ? [UIImage imageNamed:@"iGallery_select"] : nil;
        cell.accessoryView = acc;
    }
    else if (indexPath.row == 2)
    {
//        cell.textLabel.text = @"周末";
        cell.textLabel.text = NSLocalizedString(@"Weekend", nil);
        acc.image = [self.model.type isEqualToString:@"2"] ? [UIImage imageNamed:@"iGallery_select"] : nil;
        cell.accessoryView = acc;
    }
    return cell;
}

@end
